#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int binary_search(int arr[], int y,int sz)
{
	int left = 0;
	int right = sz-1;
	while(left<=right)
	{
		int mid = (left + right) / 2;
		if (arr[mid] < y)
		{
			left = mid + 1 ;
		}
		else if (arr[mid] > y)
		{
			right = mid - 1 ;
		}
		else
			return mid;
	}
	return -1;
}

int main()
{
	int arr[] = { 2, 5, 6, 7, 9, 10, 11, 17, 19, 20 };
	int a =11;
	int sz = sizeof(arr) / sizeof(arr[0]);
	int ret = binary_search(arr, a, sz);
	if ( ret== -1)
	{
		printf("The specified number could not be found\n");
	}
	else
	{
		printf("Found, subscript is: %d\n", ret);
	}
	return 0;
}